package com.barbarosso.video.view {
	import nl.demonsters.debugger.MonsterDebugger;	
	
	import com.barbarosso.video.model.VideoProxy;	
	
	import org.openvideoplayer.net.OvpNetStream;	
	
	import com.barbarosso.video.constants.VideoConst;
	import com.barbarosso.video.view.components.VideoScreen;
	
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;		

	/**
	 * @author barbarosso
	 */
	public class VideoScreenMediator extends Mediator implements IMediator {
		
		public static const NAME : String = "com.barbarosso.video.view.VideoScreenMediator";

		public function VideoScreenMediator(mediatorName : String , viewComponent : VideoScreen) {
			super(mediatorName, viewComponent);
		}
		
		override public function listNotificationInterests() : Array {
			return [VideoConst.NS_CONNECTED];
		}
		
		override public function handleNotification(notification : INotification) : void {
			MonsterDebugger.trace(this, "handleNotification = " + notification.getName());
			MonsterDebugger.trace(this, "videoProxy.ns.isLive = " + videoProxy.ns.isLive);
			switch (notification.getName()) {
				case VideoConst.NS_CONNECTED:
				{
					view.video.attachNetStream(videoProxy.ns);
					break;
				}
				default:
				{
					break;
				}
			}
		}
		
		override public function onRegister() : void {
			MonsterDebugger.trace(this, "register " + VideoScreenMediator.NAME);
		}

		private function get videoProxy() : VideoProxy {
			return facade.retrieveProxy(VideoProxy.NAME) as VideoProxy;
		}
		
		private function get view() : VideoScreen {
			return viewComponent as VideoScreen;
		}
	}
}
